package homework;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class p3425 implements ActionListener {
    JFrame jFrame;
    JTextField jTextField;

    public p3425(){
        //创建和设置Container
        jFrame=new JFrame();
        jFrame.setSize(new Dimension(300,300));
        jFrame.setLayout(new BorderLayout());
        //创建TextField
        jTextField=new JTextField();
        //注册监听器为此类本身
        jTextField.addActionListener(this);
        JLabel label=new JLabel("ActionEvent测试");
        jFrame.add("North",label);
        jFrame.add("Center",jTextField);
        jFrame.setVisible(true);
    }

    public static void main(String[] args) {
        new p3425();
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("已输入回车，并触发动作,输入的内容为：");

        if (e.getSource()==jTextField){
            System.out.println(e.getActionCommand());
            }
        }
    }





